#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：爬虫-波波老师
@File：18-xpath全部城市齐.py
@Author ：文非
@Date：2021/3/1119:54
@Require：
'''
import requests
from lxml import etree

headers = {
    'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
# 指定url
url = "https://www.aqistudy.cn/historydata/"
# 对指定url发送请求
response = requests.get(url=url, headers=headers)
page = response.text
tree = etree.HTML(page)

#  连个xpath结合 |
all_list = tree.xpath('//div[@class="bottom"]/ul/li/a | //div[@class="bottom"]/ul/div[2]/li/a')
fp = open("./全国所有城市.txt","a",encoding="utf-8")
for all in all_list:
    all = all.xpath('./text()')[0]
    fp.write(all+"\n")
print("***********抓取完成***********")

